﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MINERP.DAL;
using MINERP.DAL.CustomerManage;
using MINERP.COM;

namespace MINERP.BLL.CustomerManage
{
    public class PhotoInfoManageBLL
    {
        #region //Private fields

        #endregion


        #region //public methods

        /// <summary>
        /// 根据产品得到照片
        /// </summary>
        /// <param name="orderinfoid"></param>
        /// <returns></returns>
        public List<PhotoInfoEntity> GetPhotoInfoByOrderInfoID(int orderinfoid)
        {
            List<PhotoInfoEntity> collection = new List<PhotoInfoEntity>();

            //List<photoInfo> list = PhotoInfoDAL.GetPhotoByOrderInfoID(orderinfoid);

            //foreach (var item in list)
            //{
            //    collection.Add(new PhotoInfoEntity(item));
            //}
            using (newSampleYPDBEntities db = new newSampleYPDBEntities())
            {
                orderInfo curOrder = db.orderInfo.FirstOrDefault(o => o.OrderProductId == orderinfoid);
                if (curOrder != null)
                {
                    curOrder.photoInfo.Load();
                    foreach (var pi in curOrder.photoInfo.ToList())
                    {
                        pi.paperFaceReference.Load();
                        pi.paperTypeReference.Load();
                        collection.Add(new PhotoInfoEntity(pi,db));
                    }
                }
            }

            return collection;
        }
        /// <summary>
        /// 根据产品得到照片
        /// </summary>
        /// <param name="orderinfoid"></param>
        /// <returns></returns>
        public List<PhotoInfoEntity> GetPhotoInfoByOrderInfoID_bk(int orderinfoid)
        {
            List<PhotoInfoEntity> collection = new List<PhotoInfoEntity>();
        
            using (newSampleYPDBEntities db = new newSampleYPDBEntities())
            {
                orderInfo_BK curOrder = db.orderInfo_BK.FirstOrDefault(o => o.OrderProductId == orderinfoid);
                if (curOrder != null)
                {
                    curOrder.photoInfo_BK.Load();
                    foreach (var pi in curOrder.photoInfo_BK.ToList())
                    {
                        pi.paperFaceReference.Load();
                        pi.paperTypeReference.Load();
                        collection.Add(new PhotoInfoEntity(pi,db));
                    }
                }            
            }

            return collection;
        }

        #endregion
    }


    #region //照片实体类


    public class PhotoInfoEntity
    {
        public PhotoInfoEntity(photoInfo obj,newSampleYPDBEntities db)
        {
            printer printer = db.printer.FirstOrDefault(p=>p.PrinterID ==obj.printerId);
            if (printer != null)
            {
                PrinterName = printer.PName;
            }
            else
            {
                PrinterName = string.Empty;
            }
            PhotoBarCode = obj.PhotoBarCode;
            photoName = obj.photoName;
            Width = obj.Width;
            Height = obj.Height;
            PaperType = obj.paperType.Name;
            PaperFace = obj.paperFace.Name;
            picPath = obj.picPath;
            Remark = obj.Remark;
            Status = GetStatusName(obj.status);
        }
        public PhotoInfoEntity(photoInfo_BK obj,newSampleYPDBEntities db)
        {
            printer printer = db.printer.FirstOrDefault(p => p.PrinterID == obj.printerId);
            if (printer != null)
            {
                PrinterName = printer.PName;
            }
            else
            {
                PrinterName = string.Empty;
            }
            PhotoBarCode = obj.PhotoBarCode;
            photoName = obj.photoName;
            Width = obj.Width;
            Height = obj.Height;
            PaperType = obj.paperType.Name;
            PaperFace = obj.paperFace.Name;
            picPath = obj.picPath;
            Remark = obj.Remark;
            Status = GetStatusName(obj.status);
        }

        private string GetStatusName(int stats)
        {
            switch ((PhotoStatus)stats)
            {
                case PhotoStatus.NoDistributePrinter:
                    return "未分配打印机";
                    break;
                case PhotoStatus.DistributedPrinter:
                    return "等待拼板";
                    break;
                case PhotoStatus.PingBan:
                    return "等待生成大图";
                    break;
                case PhotoStatus.Printed:
                    return "已打印等待分片";
                    break;
                case PhotoStatus.FenPian:
                    return "已分片";
                    break;
                case PhotoStatus.WaitPhotoMove:
                    return "等待移动图片";
                    break;
                case PhotoStatus.PhotoNotExist:
                    return "图片不存在";
                    break;
                default:
                    return "完成";
                    break;
            }
        }

        #region //public priorities
        public string Status { get; set; }

        public string PhotoBarCode
        {
            get;
            set;
        }

        public string photoName
        {
            get;
            set;
        }

        public double Width
        {
            get;
            set;
        }

        public double Height
        {
            get;
            set;
        }

        public string PaperType
        {
            get;
            set;
        }

        public string PaperFace
        {
            get;
            set;
        }

        public string picPath
        {
            get;
            set;
        }

        public string Remark
        {
            get;
            set;
        }
        public string PrinterName
        {
            get;
            set;
        }
        /*
        public string PhotoBarCode
        {
            get
            {
                return this._obj.PhotoBarCode;
            }
        }

        public string photoName
        {
            get
            {
                return this._obj.photoName;
            }
        }

        public double Width
        {
            get
            {
                return this._obj.Width;
            }
        }

        public double Height
        {
            get
            {
                return this._obj.Height;
            }
        }

        public string PaperType
        {
            get
            {
                return this._obj.paperType.Name;
            }
        }

        public string PaperFace
        {
            get
            {
                return this._obj.paperFace.Name;
            }
        }

        public string picPath
        {
            get
            {
                return this._obj.picPath;
            }
        }

        public string Remark
        {
            get
            {
                return this._obj.Remark;
            }
        }*/

        #endregion
    }

    #endregion
}
